home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / source / sprites / fast32.asm < prev    next >
Encoding:
Assembly Source File  |  1993-04-02  |  6.5 KB  |  279 lines

  1.     page ,132
  2.     TITLE FAST32.ASM
  3. ;---------------------------------------------------------------------------;
  4. ;  FAST.ASM
  5. ;
  6. ;  32 bit asm routines for doing a "sprite" bitblt
  7. ;
  8. ;      TransCopyDIBBits - copy DIB bits with a transparent color
  9. ;      CopyDIBBits      - copy DIB bits without a transparent color
  10. ;
  11. ;---------------------------------------------------------------------------;
  12.  
  13. ;
  14. ; 32 bit code segment version of FAST16.ASM
  15. ; General technology courtesy of Todd Laney
  16. ;
  17. ; NOTE! cmacro32.inc NEEDS MASM 5.1 (or compatible)
  18. ; you would think MASM 6 would be compatible but it isn't
  19. ;
  20.     .xlist
  21.     include cmacro32.inc
  22.     .list
  23.  
  24. ;
  25. ; NOTE!!!! because we are generating USE32 code this must NOT
  26. ; be located in a code segment with USE16 code, so we put it into
  27. ; it's own little segment....
  28. ;
  29.  
  30. ifndef SEGNAME
  31.     SEGNAME equ <FAST_TEXT32>
  32. endif
  33.  
  34. createSeg %SEGNAME, CodeSeg, word, use32, CODE
  35.  
  36. sBegin Data
  37. sEnd Data
  38.  
  39. sBegin CodeSeg
  40.         assumes cs,CodeSeg
  41.         assumes ds,nothing
  42.         assumes es,nothing
  43.  
  44. ;-------------------------------------------------------
  45. ;
  46. ; TransCopyDIBBits
  47. ;
  48. ; Copy a block with transparency
  49. ;
  50. ;-------------------------------------------------------
  51.  
  52. cProc TransCopyDIBBits,<FAR, PASCAL, PUBLIC>,<>
  53.         ParmD   pDest           ; dest pointer
  54.         ParmD   pSource         ; source pointer
  55.         ParmD   dwWidth         ; width pixels
  56.         ParmD   dwHeight        ; height pixels
  57.         ParmD   dwScanD         ; width bytes dest
  58.         ParmD   dwScanS         ; width bytes source
  59.         ParmB   bTranClr        ; transparent color
  60. cBegin
  61.         push ds
  62.         push esi
  63.         push edi
  64.  
  65.         mov ecx, dwWidth
  66.         or ecx,ecx
  67.         jz tcdb_nomore     ; test for silly case
  68.  
  69.         mov edx, dwHeight       ; EDX is line counter
  70.         mov ah, bTranClr        ; AL has transparency color
  71.  
  72.         xor esi, esi
  73.         lds si, pSource         ; DS:[ESI] point to source
  74.  
  75.         xor edi, edi
  76.         les di, pDest           ; ES:[EDI] point to dest
  77.  
  78.         sub dwScanD,ecx         ; bias these
  79.         sub dwScanS,ecx
  80.  
  81.         mov ebx,ecx             ; save this for later
  82.  
  83.         align 4
  84. tcdb_morelines:
  85.         mov ecx, ebx            ; ECX is pixel counter
  86.         shr ecx,2
  87.         jz  short tcdb_nextscan
  88.  
  89. ;
  90. ; The idea here is to not branch very often so we unroll the loop by four
  91. ; and try to not branch when a whole run of pixels is either transparent
  92. ; or not transparent.
  93. ;
  94. ; There are two loops. One loop is for a run of pixels equal to the
  95. ; transparent color, the other is for runs of pixels we need to store.
  96. ;
  97. ; When we detect a "bad" pixel we jump to the same position in the
  98. ; other loop.
  99. ;
  100. ; Here is the loop we will stay in as long as we encounter a "transparent"
  101. ; pixel in the source.
  102. ;
  103.  
  104.         align 4
  105. tcdb_same:
  106.         mov al, ds:[esi]
  107.         cmp al, ah
  108.         jne short tcdb_diff0
  109.  
  110. tcdb_same0:
  111.         mov al, ds:[esi+1]
  112.         cmp al, ah
  113.         jne short tcdb_diff1
  114.  
  115. tcdb_same1:
  116.         mov al, ds:[esi+2]
  117.         cmp al, ah
  118.         jne short tcdb_diff2
  119.  
  120. tcdb_same2:
  121.         mov al, ds:[esi+3]
  122.         cmp al, ah
  123.         jne short tcdb_diff3
  124.  
  125. tcdb_same3:
  126.         add edi,4
  127.         add esi,4
  128.         dec ecx
  129.         jnz short tcdb_same
  130.         jz  short tcdb_nextscan
  131.  
  132. ;
  133. ; Here is the loop we will stay in as long as 
  134. ; we encounter a "non transparent" pixel in the source.
  135. ;
  136.  
  137.         align 4
  138. tcdb_diff:
  139.         mov al, ds:[esi]
  140.         cmp al, ah
  141.         je short tcdb_same0
  142.  
  143. tcdb_diff0:
  144.         mov es:[edi],al
  145.         mov al, ds:[esi+1]
  146.         cmp al, ah
  147.         je short tcdb_same1
  148.  
  149. tcdb_diff1:
  150.         mov es:[edi+1],al
  151.         mov al, ds:[esi+2]
  152.         cmp al, ah
  153.         je short tcdb_same2
  154.  
  155. tcdb_diff2:
  156.         mov es:[edi+2],al
  157.         mov al, ds:[esi+3]
  158.         cmp al, ah
  159.         je short tcdb_same3
  160.  
  161. tcdb_diff3:
  162.         mov es:[edi+3],al
  163.  
  164.         add edi,4
  165.         add esi,4
  166.         dec ecx
  167.         jnz short tcdb_diff
  168.         jz  short tcdb_nextscan
  169.  
  170. ;
  171. ; We are at the end of a scan, check for odd leftover pixels to do
  172. ; and go to the next scan.
  173. ;
  174.  
  175.         align 4
  176. tcdb_nextscan:
  177.         mov ecx,ebx
  178.         and ecx,11b
  179.         jnz short tcdb_oddstuff
  180.         ; move on to the start of the next line
  181.  
  182. tcdb_nextscan1:
  183.         add esi, dwScanS
  184.         add edi, dwScanD
  185.  
  186.         dec edx                 ; line counter
  187.         jnz short tcdb_morelines
  188.         jz  short tcdb_nomore
  189.  
  190. ;
  191. ; If the width is not a multiple of 4 we will come here to clean up
  192. ; the last few pixels
  193. ;
  194.  
  195. tcdb_oddstuff:
  196.         inc ecx
  197. tcdb_oddloop:
  198.         dec ecx
  199.         jz  short tcdb_nextscan1
  200.         mov al, ds:[esi]
  201.         inc esi
  202.         inc edi
  203.         cmp al, ah
  204.         je  short tcdb_oddloop
  205.         mov es:[edi-1],al
  206.         jmp short tcdb_oddloop
  207.  
  208. tcdb_nomore:
  209.         pop edi
  210.         pop esi
  211.         pop ds
  212. cEnd
  213.  
  214. ;-----------------------------------------------------------------------------;
  215. ;
  216. ; CopyDIBBits
  217. ;
  218. ; Copy a block without transparency
  219. ;
  220. ;-----------------------------------------------------------------------------;
  221.  
  222. cProc CopyDIBBits,<FAR, PASCAL, PUBLIC>,<>
  223.         ParmD   pDest           ; dest pointer
  224.         ParmD   pSource         ; source pointer
  225.         ParmD   dwWidth         ; width pixels
  226.         ParmD   dwHeight        ; height pixels
  227.         ParmD   dwScanD         ; width bytes dest
  228.         ParmD   dwScanS         ; width bytes source
  229. cBegin
  230.         push ds
  231.         push esi
  232.         push edi
  233.  
  234.         mov ecx, dwWidth
  235.         or ecx,ecx
  236.         jz cdb_nomore     ; test for silly case
  237.  
  238.         mov edx, dwHeight       ; EDX is line counter
  239.         or edx,edx
  240.         jz cdb_nomore     ; test for silly case
  241.  
  242.         xor esi, esi
  243.         lds si, pSource         ; DS:[ESI] point to source
  244.  
  245.         xor edi, edi
  246.         les di, pDest           ; ES:[EDI] point to dest
  247.  
  248.         sub dwScanD,ecx         ; bias these
  249.         sub dwScanS,ecx
  250.  
  251.         mov ebx,ecx
  252.         shr ebx,2
  253.  
  254.         mov eax,ecx
  255.         and eax,11b
  256.  
  257.         align 4
  258. cdb_loop:
  259.         mov ecx, ebx
  260.         rep movs dword ptr es:[edi], dword ptr ds:[esi]
  261.         mov ecx,eax
  262.         rep movs byte ptr es:[edi], byte ptr ds:[esi]
  263.  
  264.         add esi, dwScanS
  265.         add edi, dwScanD
  266.         dec edx                 ; line counter
  267.         jnz short cdb_loop
  268.  
  269. cdb_nomore:
  270.         pop edi
  271.         pop esi
  272.         pop ds
  273. cEnd
  274.  
  275.  
  276.  
  277. sEnd CodeSeg
  278. end
  279.